import { BadRequestException, PipeTransform } from '@nestjs/common'

export class ParseBoolPipe implements PipeTransform<string, Promise<boolean>>{
   async transform(value: string): Promise<boolean> {
    if (value.toLowerCase() === 'true') {
      return true
    } else if (value.toLowerCase() === 'false') {
      return false
    } else {
      throw new BadRequestException(`Validation failed (boolean string is expected)`, 'Bad Request')
    }
  }
}
